package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateSemestersYearGroupsDialog;
import pl.prv.polanie.client.dto.CSSemestersYearGroupsDTO;
import pl.prv.polanie.client.dto.CSVSemestersYearGroupsDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableSemestersYearGroups;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class SemestersYearGroupsList extends ObjectsList {

	TableSemestersYearGroups tableSemestersYearGroups = new TableSemestersYearGroups(this);

	public SemestersYearGroupsList() {
		
		CSSemestersYearGroupsDTO[] ls = Cache.getAllSemestersYearGroups();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableSemestersYearGroups);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSSemestersYearGroupsDTO cs = ls[i];
			CSVSemestersYearGroupsDTO csv = ViewDataProvider.getCSVSemestersYearGroups(cs);
			
			tableSemestersYearGroups.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateSemestersYearGroupsDialog csygd = new CreateSemestersYearGroupsDialog(SemestersYearGroupsList.this, null); 
				csygd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableSemestersYearGroups.removeSelectedSemestersYearGroupFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSSemestersYearGroup(CSSemestersYearGroupsDTO csSemestersYearGroup) {
//		CSVSemestersYearGroupDTO csv = ViewDataProvider.getCSVSemestersYearGroup(csSemestersYearGroup);
		
		tableSemestersYearGroups.saveOrUpdateSemestersYearGroupInTable(csSemestersYearGroup);
//		tableSemestersYearGroups.addRow(csSemestersYearGroup, csv);
	}
	
	public void removeSelectdCSSemestersYearGroup() {
		tableSemestersYearGroups.removeSelectedSemestersYearGroupFromTable();
	}
	
}
